<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">  

<head>    
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

<title>Search</title>
    
<script src="http://www.google.com/jsapi?key=ABQIAAAAKBtykkdToRdw8KTqfIk7uRTud6Zx91aXovon844wSdVhboCw4xRi2PV_6LdGZ5TcfVMzdVY3D3K1qQ" type="text/javascript"></script>    <script language="Javascript" type="text/javascript">    
//<![CDATA[    
//google.load("search", "1");    
function OnLoad() {      
	// Create a search control     
	var searchControl = new google.search.SearchControl();      
	// Add in a full set of searchers     
	var localSearch = new google.search.LocalSearch();      
	searchControl.addSearcher(localSearch);      
	searchControl.addSearcher(new google.search.WebSearch());      
	searchControl.addSearcher(new google.search.VideoSearch());      
	searchControl.addSearcher(new google.search.BlogSearch());      
	// Set the Local Search center point     
	localSearch.setCenterPoint("New York, NY");      
	// Tell the searcher to draw itself and tell it where to attach      
	searchControl.draw(document.getElementById("searchcontrol"));      
	// Execute an inital search      
	searchControl.execute("Google");    
}    
//google.setOnLoadCallback(OnLoad);    
//]]>    </script>  
</head>  
<body>    
<div id="searchcontrol" style="display:none">Loading...</div>  </body></html>





<form method="post" enctype="multipart/form-data" > 
<table class="form" width="350" height="98" border="0" cellpadding="0" cellspacing="0"> 
<tr><td width="10" height="10"></td></tr> 
<tr> 
	<td width="10"></td> 
	<td> 
	<table width="100%" border="0" cellpadding="0" cellspacing="0"> 
	<tr> 
		<td><div align="right"><label for="auth_login">Key phrase:</label></div></td> 
		<td width="5"></td> 
		<td width="200"><input class="input" type="text" name="q" value="<? echo $_POST['q'] ?>" size="30" height="14" /></td> 
	</tr> 
	<tr> 
		<td><div align="right">Categories:</div></td> 
		<td ></td> 
		<td >
			<input class="input" type="checkbox" name="urlTypes[]" value="0" checked="checked" />&nbsp;General<br />
			<!--<input class="input" type="checkbox" name="urlTypes[]" value="1" />&nbsp;Video<br />-->
			<input class="input" type="checkbox" name="urlTypes[]" value="2" />&nbsp;Blogs<br />
			<input class="input" type="checkbox" name="urlTypes[]" value="3" />&nbsp;News<br />
			<!--<input class="input" type="checkbox" name="urlTypes[]" value="4" />&nbsp;Books<br />-->
			<!--<input class="input" type="checkbox" name="urlTypes[]" value="5" />&nbsp;Images<br />-->
			<!--<input class="input" type="checkbox" name="urlTypes[]" value="6" />&nbsp;Patents<br />-->
		</td> 
	</tr> 
	<tr> 
		<td><div align="right"> </div></td> 
		<td ></td> 
		<td ><input class="input" type="submit" name="submit" value="Submit" height="14" /></td> 
	</tr> 

	</table></td> 
    <td width="30"></td> 
</tr> 
<tr> 
	<td colspan="3" height="10"></td> 
</tr> 
</table> 
</form> 
<hr>








<?

$apiUrls = array();
$apiUrls[0] = "web"; 
$apiUrls[1] = "video"; 
$apiUrls[2] = "blogs"; 
$apiUrls[3] = "news"; 
$apiUrls[4] = "books"; 
$apiUrls[5] = "images"; 
$apiUrls[6] = "patent"; 


$params = $_POST;
$results = array();

if ($params) {
	$searchString = urlencode($params["q"]);
	foreach ($urlTypes as $urlType){
		$urlTypeID = $urlType;
		$urlType = $apiUrls[$urlType];
		$url = "http://ajax.googleapis.com/ajax/services/search/$urlType?v=1.0&q=$searchString&filter=1"; 
		$ch = curl_init(); 
		curl_setopt($ch, CURLOPT_URL, $url); 
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
		curl_setopt($ch, CURLOPT_REFERER, "http://www.w3monitor.com/search.php"); 
		$body = curl_exec($ch); 
		curl_close($ch); 
		$json = json_decode($body); 
		
		foreach ($json as $item){

			foreach ($item as $item1){
				//if ($key1=="results") {
					echo "<pre>";
						//var_dump($item1);
						echo "</pre>";
					foreach ($item1 as $item2){
						if ($urlType=="web") {
							$resultItem = array();
							$resultItem["url"] = $item2->visibleUrl;
							$resultItem["urldisplay"] = $item2->unescapedUrl;
							$resultItem["title"] = $item2->title;
							$resultItem["content"] = $item2->content;
							$results["web"]["results"][] = $resultItem;
							$results["web"]["name"] = "General";
						} elseif ($urlType=="blogs") {
							$resultItem = array();
							$resultItem["url"] = $item2->postUrl;
							$resultItem["urldisplay"] = $item2->blogUrl;
							$resultItem["title"] = $item2->title;
							$resultItem["content"] = $item2->content;
							$results["blog"]["results"][] = $resultItem;
							$results["blog"]["name"] = "Blogs";
						} elseif ($urlType=="news") {
							$resultItem = array();
							$resultItem["url"] = $item2->url;
							$resultItem["urldisplay"] = $item2->unescapedUrl;
							$resultItem["title"] = $item2->title;
							$resultItem["content"] = $item2->content;
							$results["news"]["results"][] = $resultItem;
							$results["news"]["name"] = "News";
						}
					}	
				//}
			}
		}	

		
		echo "<pre>";
		//var_dump($json);
		//var_dump($results);
		echo "</pre>";
	}
	
	
	
	
}

//if (count($results["news"])>0) {


	foreach ($results as $result){
		echo "<h3>".$result["name"]."</h3>";
		foreach ($result["results"] as $resultItem){
			if ($resultItem["url"]){
				echo "<span style='color : #00ccff'>".$resultItem["title"]."</span><br>";
				echo $resultItem["content"]."<br>";
				echo " - ".$resultItem["urldisplay"]."<br>";
				echo "<a target='_blank' href='".$resultItem["url"]."'>[View in new window]</a><br><br>";
				
				
			}
		}
	}
//}


?>